package com.wenlin.myproduction.bean;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.google.gson.annotations.Expose;
import com.wenlin.myproduction.util.TestDefaultDataUtil;

import java.io.Serializable;
import java.util.List;

public class ResEn implements Parcelable {
    @Expose
    public int ResId;
    @Expose
    public String ResName;
    @Expose
    public String CoverPic;
    @Expose
    public String ResProfile;
    @Expose
    public String ResCaptions;
    @Expose
    public String CreateUserName;
    @Expose
    public int ViewCounts;
    @Expose
    public String ResPackageUrl;
    @Expose
    public int DiamondCost;
    @Expose
    public int ChangeCost;
    @Expose
    public String CreateTime;

    public String UserName;

    public String localFile;

    @Expose
    public boolean SingFlag;
    @Expose
    public String ResUrl;
    @Expose
    public List<ShootVideoEn> ShootVideoList;
    @Expose
    public ShootVideoEn MyInfo;
    @Expose
    public boolean RecordFlag;
    @Expose
    public String Title;
    @Expose
    public int RecordId;
    @Expose
    public String RecordUrl;

    public ResEn(){

    }

    protected ResEn(Parcel in) {
        ResId = in.readInt();
        ResName = in.readString();
        CoverPic = in.readString();
        ResProfile = in.readString();
        ResCaptions = in.readString();
        CreateUserName = in.readString();
        ViewCounts = in.readInt();
        ResPackageUrl = in.readString();
        DiamondCost = in.readInt();
        ChangeCost = in.readInt();
        CreateTime = in.readString();
        UserName = in.readString();
        localFile = in.readString();
        SingFlag = in.readByte() != 0;
        ResUrl = in.readString();
        ShootVideoList = in.createTypedArrayList(ShootVideoEn.CREATOR);
        MyInfo = in.readParcelable(ShootVideoEn.class.getClassLoader());
        RecordFlag = in.readByte() != 0;
        Title = in.readString();
        RecordId = in.readInt();
        RecordUrl = in.readString();
        ResourceList = in.createTypedArrayList(ResourceEn.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(ResId);
        dest.writeString(ResName);
        dest.writeString(CoverPic);
        dest.writeString(ResProfile);
        dest.writeString(ResCaptions);
        dest.writeString(CreateUserName);
        dest.writeInt(ViewCounts);
        dest.writeString(ResPackageUrl);
        dest.writeInt(DiamondCost);
        dest.writeInt(ChangeCost);
        dest.writeString(CreateTime);
        dest.writeString(UserName);
        dest.writeString(localFile);
        dest.writeByte((byte) (SingFlag ? 1 : 0));
        dest.writeString(ResUrl);
        dest.writeTypedList(ShootVideoList);
        dest.writeParcelable(MyInfo, flags);
        dest.writeByte((byte) (RecordFlag ? 1 : 0));
        dest.writeString(Title);
        dest.writeInt(RecordId);
        dest.writeString(RecordUrl);
        dest.writeTypedList(ResourceList);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<ResEn> CREATOR = new Creator<ResEn>() {
        @Override
        public ResEn createFromParcel(Parcel in) {
            return new ResEn(in);
        }

        @Override
        public ResEn[] newArray(int size) {
            return new ResEn[size];
        }
    };

    public String getUserName() {
        if(TextUtils.isEmpty(CreateUserName)){
            CreateUserName = TestDefaultDataUtil.getRondomName();
        }
        return CreateUserName;
    }

    @Expose
    public List<ResourceEn> ResourceList;


    public static class ResourceEn implements Parcelable {
        @Expose
        public String resource_url;
        @Expose
        public String resource_url2;
        @Expose
        public List<SentenceEn> sentence;
        @Expose
        public String subtitles_url;
        @Expose
        public String subtitles_url2;


        protected ResourceEn(Parcel in) {
            resource_url = in.readString();
            sentence = in.createTypedArrayList(SentenceEn.CREATOR);
            subtitles_url = in.readString();
            resource_url2 = in.readString();
            subtitles_url2 = in.readString();
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(resource_url);
            dest.writeTypedList(sentence);
            dest.writeString(subtitles_url);
            dest.writeString(resource_url2);
            dest.writeString(subtitles_url2);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<ResourceEn> CREATOR = new Creator<ResourceEn>() {
            @Override
            public ResourceEn createFromParcel(Parcel in) {
                return new ResourceEn(in);
            }

            @Override
            public ResourceEn[] newArray(int size) {
                return new ResourceEn[size];
            }
        };
    }
//    @Entity
    public static class SentenceEn implements Parcelable, Serializable {
        private static final long serialVersionUID = 4254657069809818234L;
        @Expose
        public String audioUrl;

        @Expose
        public String text;

        protected SentenceEn(Parcel in) {
            audioUrl = in.readString();
            text = in.readString();
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(audioUrl);
            dest.writeString(text);
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<SentenceEn> CREATOR = new Creator<SentenceEn>() {
            @Override
            public SentenceEn createFromParcel(Parcel in) {
                return new SentenceEn(in);
            }

            @Override
            public SentenceEn[] newArray(int size) {
                return new SentenceEn[size];
            }
        };
    }
}
